<template>
	<view class="page">
		<template v-if="isLogin">
			<view class="category-list row-2">
				<navigator url="/package_shibie/dataList/dataList" open-type="navigate" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/ysb_datas.png" mode="widthFix"></image></view>
					<view class="text">识别记录</view>
				</navigator>
				<!-- <navigator url="/package_yunpeixun/dataList/dataList" open-type="navigate" hover-class="none" class="item">
					<view class="icon"><image src="@/static/images/export.png" mode="widthFix"></image></view>
					<view class="text">培训数据</view>
				</navigator> -->
			</view>
			<view class="start-btn-area">
				<view class="btn" @click="flag.isFullPage=true;flag.isChangeType=true">
					<image src="@/static/images/yc_start.png" mode="widthFix"></image>
				</view> 
			</view>
			 
			
			<view v-if="flag.isFullPage" class="full-fix-page">
				<view v-if="flag.isChangeType" class="bottom-tab-btn a-fadeinB">
					<view class="bottom-lay-btn-wrap m-b2">
						<view class="lay-btn" @click="checkPhoto">从相册选择</view>
						<navigator url="/package_shibie/camera/camera" hover-class="none" class="lay-btn">拍照</navigator>
					</view>
					<view class="bottom-lay-btn-wrap m-b2" @click="flag.isFullPage=false;flag.isChangeType=false">
						<view class="lay-btn">取消</view> 
					</view> 
				</view>
			</view>
			 
		</template>
	</view>
</template>

<script>
	import {
		HTTP_OLD_HOST,
		WEB_HOST
	} from '@/config.js'
	import {
		dateFormat,
		uploadImage, 
		uploadToServe, 
	} from '@/common/util.js'
	export default {
		name: 'name',
		data() {
			return { 
				isLogin: false, 
				userInfo: uni.getStorageSync('userInfo'),
				loginStateUpdate: false,
				app_name: getApp().globalData.app_name,
				files:[],
				flag:{
					isFullPage:false,
					isChangeType:false
				},
			}


		},
		async onLoad() {			
			this.isLogin=await this.$loginState('check');  
		},
		async onShow() {

		},
		onUnload() {
			this.flag.isFullPage=false;
			this.flag.isChangeType=false
		},
		onHide() {
			this.flag.isFullPage=false;
			this.flag.isChangeType=false
		},
		methods: {
			checkPhoto:async function(){ 
				// 上传现场照片
				let _this = this;
				uploadImage({
					length: _this.files.length,
					sourceType:['album'],
					maxSize: 1, 
					async success(res) {  
						let params_data = {};
						params_data.status = 0;
						params_data.url = res.tempFilePaths[0];
						_this.files.push(params_data); 
						let token=await _this.$api.user_api.getToken({
							appid:'100002',
							appsecret:'24dcb652ce0043c9a53d90de2468b5b8'
						}) 
						uni.showLoading();
						uploadToServe({
							type:1,
							url: 'https://shibie.honghuoyi.com/user/sb-insert.do', 
							filePath: res.tempFilePaths[0],
							name: 'myfile',
							formData:{
								appid:100002,
								token:token.data.data.token,
								uid:_this.userInfo.id
							}
						}).then((up_res) => {  
							uni.hideLoading();
							if (up_res.ret == 1000) {	 
								uni.navigateTo({
									url:'/package_shibie/dataList/dataList'
								})
							}
						}) 
						
						// uploadToServe({
						// 	url: '/yfk/upload-file',
						// 	filePath: res.tempFilePaths[0],
						// 	name: 'photo',
						// 	formData: {
						// 		'p_id': 0,
						// 		'uid': _this.userInfo.id
						// 	}
						// }).then((up_res) => { 
						// 	if (up_res.ret == 0) {								
						// 		params_data.file_name = up_res.data.file_name;
						// 		params_data.file_path = up_res.data.file_path;
						// 		params_data.file_type = up_res.data.file_type;
						// 		params_data.status = up_res.data.status;
						// 		params_data.type = up_res.data.type; 								
						// 	}
						// }).catch((err)=>{
						// 	console.log(err)
						// })
					}
				})

			},
			
			// 打开弹窗
			showPopup:function(t,n){
				if(t=='show'){
					this.flag.isFullPage=true;
					this.flag[n]=true;
				}else if(t=='hide'){
					for(let i in this.flag){
						this.flag[i]=false;
					}
				}
			},
			
		},
		components: {

		},

		computed: {

		},
		watch: {

		}

	}
</script>

<style lang="less" scoped> 
	.category-list{
		background: #fff;
		margin-bottom: 20rpx;
		padding: 20rpx 0 0;
		.item{
			.icon{
				width: 30%!important;
			}
		}
	}
	.name {
		text-align: center;

		text {
			padding-top: 10rpx;
			border-top: 2rpx dashed #999;
			font-size: 28rpx;
			color: #999;
		}
	}
	.start-btn-area{
		position:absolute;
		left:0;
		bottom:150rpx;
		width:100%;
	}

	.btn {
		width: 60%;
		margin: 0 auto;
		image {
			width: 100%;
		}
	}
	.check-photo{
		text-align: center;
		font-size: 28rpx;
	}
	
</style>
